package com.ddone.ioc.demo.service;

import com.ddone.ioc.demo.bean.Address;
import com.ddone.ioc.demo.config.DemoConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author ddone
 * @date 2024/3/19-16:09
 */
public class BeanAnnoTest {
    AnnotationConfigApplicationContext context;
    @Before
    public void init() {
        //1.创建容器对象
        //ClassPathXmlApplicationContext -> 类路径下的xml配置
        //AnnotationConfigApplicationContext -> 注解方式的配置的容器
        context = new AnnotationConfigApplicationContext(DemoConfig.class);
    }

    @After
    public void destroy(){
        // 3. 关闭容器对象
        context.close();
    }
    @Test
    public void testAnnoBean(){
        Address address = context.getBean("address", Address.class);
        System.out.println("address = " + address);
    }
}
